*****************************************************************************************************************************************************
* PROJECT: 		Exposure to the COVID-19 Stock Market Crash and its Effect on Household Expectations
* DATE: 		Nov 2020
* CONTENT: 		FIGURES
* AUTHORS: 		Tobin Hanspal, Johannes Wohlfart, Anni Weber
*****************************************************************************************************************************************************

		clear all
		set scheme lean2
		global pm = char(177)
		set more off
		gl date = c(current_date)
		graph set window fontface "cmr10"
		
		
* set cd as /Replication_files_HanspalWeberWohlfart2020/

*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~						
** FIGURE A20
*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~	

use data/processed/data_1, clear	

gen riskshare_retirwealth_Jan201=riskshare_retirwealth_Jan20
gen riskshare_ofinwealth_Jan201=riskshare_ofinwealth_Jan20
replace riskshare_retirwealth_Jan201=0 if retirJan20_0==1
replace riskshare_ofinwealth_Jan201=0 if ofinJan20_0==1
gen stockinvestor_retire=riskshare_retirwealth_Jan201>0 if riskshare_retirwealth_Jan201!=.
gen stockinvestor_ofin=riskshare_ofinwealth_Jan201>0 if riskshare_ofinwealth_Jan201!=.
gen delhhnetinc_USD_tr02alt_qtr_cond = delhhnetinc_USD_tr02alt_qtr if jobloss_20q1==1
gen del_hhnetinc_perc_tr02_cond = del_hhnetinc_perc_tr02 if jobloss_20q1==1
	
* Scale USD variables	
	foreach x in  delofin_USD_tr02 delretir_USD_tr02  delfinwealth_USD_tr02   delhhnetinc_USD_tr02 delofin_USD_tr02alt delretir_USD_tr02alt  delfinwealth_USD_tr02alt {
		replace `x' = `x'/1000
	}
	foreach x in ofinwealth_lvl retirewealth_lvl  finwealth_Jan20 hhinc_lvl hhnetinc_2019   {
		replace `x' = `x'/1000
	}

* gen conditional variables:
	gen del_ofin_perc_tr02_cond = del_ofin_perc_tr02
	replace del_ofin_perc_tr02_cond = . if stockinvestor_ofin!=1
	gen del_retir_perc_tr02_cond = del_retir_perc_tr02
	replace del_retir_perc_tr02_cond = . if stockinvestor_retire!=1
	gen del_finwealth_perc_tr02_cond = del_finwealth_perc_tr02
	replace del_finwealth_perc_tr02_cond = . if stockowner!=1
	gen delofin_USD_tr02_cond = delofin_USD_tr02
	replace delofin_USD_tr02_cond = . if stockinvestor_ofin!=1
	gen delretir_USD_tr02_cond = delretir_USD_tr02
	replace delretir_USD_tr02_cond = . if stockinvestor_retire!=1
	gen delfinwealth_USD_tr02_cond = delfinwealth_USD_tr02
	replace delfinwealth_USD_tr02_cond = . if stockowner!=1

* gen extensive margin vars:
	gen del_ofin_d = (del_ofin_perc_tr02<0) if  del_ofin_perc_tr02!=. 
	replace del_ofin_d = . if stockinvestor_ofin!=1
	
	gen del_retire_d = (del_retir_perc_tr02<0) if  del_retir_perc_tr02!=. 
	replace del_retire_d = . if stockinvestor_retire!=1
	
	gen del_finwealth_d = (del_finwealth_perc_tr02<0) if  del_finwealth_perc_tr02!=. 
	replace del_finwealth_d = . if stockowner!=1

	gen riskshare_5 = .
	replace riskshare_5=1 if riskshare_finwealth_Jan201>=0 &riskshare_finwealth_Jan201<=20 & riskshare_finwealth_Jan201!=.
	replace riskshare_5=2 if riskshare_finwealth_Jan201>20 &riskshare_finwealth_Jan201<=40 & riskshare_finwealth_Jan201!=.
	replace riskshare_5=3 if riskshare_finwealth_Jan201>40 &riskshare_finwealth_Jan201<=60 & riskshare_finwealth_Jan201!=.
	replace riskshare_5=4 if riskshare_finwealth_Jan201>60 &riskshare_finwealth_Jan201<=80 & riskshare_finwealth_Jan201!=.
	replace riskshare_5=5 if riskshare_finwealth_Jan201>80 &riskshare_finwealth_Jan201<=100 & riskshare_finwealth_Jan201!=.

	keep if control_pure==1	

	gen employment_type = employment_situation
	replace employment_type = . if employment_type!=1 & employment_type!=2 & employment_type!=9 & employment_type!=5
	label values employment_type employment 		

	label define educationshort ///
	1 "Less HS" 2 "HS" 3 "Some" 4 "Assoc." ///
	5 "Bach." 6 "Grad."
	label values education educationshort 
	
  
* CHANGE IN FINANCAIAL WEALTH  
  
  * change in fin wealth by netwealth
	graph bar (mean)  del_ofin_perc_tr02 del_retir_perc_tr02  del_finwealth_perc_tr02,  ///
		over(education, relabel(1 "Less HS" 2`" "High" "School" "'3 `" "Some"  "College" "' 4 `" "Assoc." "Deg." "'5 `" "Bach." "Deg." "'6 `" "Grad." "Deg." "') label(labsize(vsmall))) b1title("",  size(small)) ///
		  bargap(0)  /// 
		ytitle("Change in financial wealth (%)", size(medsmall)) ///
		yline(0, lcolor(gs8) lpattern(dash)) graphregion(color(white)) bgcolor(white) ///
		ylabel(-20(5)0, nogrid)  legend(size(small) symxsize(3) symysize(3)  pos(6) ring(1) cols(6) ///
		label(1 "Other financial wealth") label(2 "Retirement wealth") ///
		label(3 "Total financial wealth")) saving(Figures/temp1.gph, replace)
		
  * change in fin wealth by netwealth
	graph bar (mean)  del_ofin_perc_tr02 del_retir_perc_tr02  del_finwealth_perc_tr02,  ///
		over(gender, relabel(1 "Male" 2 "Female") label(labsize(vsmall))) b1title("",  size(small)) ///
		  bargap(0)  /// 
		ytitle("", size(medsmall)) ///
		yline(0, lcolor(gs8) lpattern(dash)) graphregion(color(white)) bgcolor(white) ///
		ylabel(-20(5)0, nogrid)  legend(size(small) symxsize(3) symysize(3)  pos(6) ring(1) cols(6) ///
		label(1 "Other financial wealth") label(2 "Retirement wealth") ///
		label(3 "Total financial wealth")) saving(Figures/temp2.gph, replace)
		
	 * change in fin wealth by netwealth
	graph bar (mean)  del_ofin_perc_tr02 del_retir_perc_tr02  del_finwealth_perc_tr02,  ///
		over(employment_type,  relabel(1 "Full time" 2 "Part time" 3 "Retired" 4 "Self-emp" )  label(labsize(vsmall)))b1title("",  size(small)) ///
		  bargap(0)  /// 
		ytitle("", size(medsmall)) ///
		yline(0, lcolor(gs8) lpattern(dash)) graphregion(color(white)) bgcolor(white) ///
		ylabel(-20(5)0, nogrid)  legend(size(small) symxsize(3) symysize(3)  pos(6) ring(1) cols(6) ///
		label(1 "Other financial wealth") label(2 "Retirement wealth") ///
		label(3 "Total financial wealth")) 	saving(Figures/temp3.gph, replace)		
		
* Change in netincome		
	  * change in fin wealth by netwealth
	graph bar (mean)  del_hhnetinc_perc_tr02,  ///
		over(education, relabel(1 "Less HS" 2`" "High" "School" "'3 `" "Some"  "College" "' 4 `" "Assoc." "Deg." "'5 `" "Bach." "Deg." "'6 `" "Grad." "Deg." "')  label(labsize(vsmall))) b1title("Highest level of education achieved",  size(small)) ///
		  bargap(0)  /// 
		ytitle("Change in net income (%)", size(medsmall)) ///
		yline(0, lcolor(gs8) lpattern(dash)) graphregion(color(white)) bgcolor(white) ///
		ylabel(-12.5(2.5)0, nogrid)  legend(size(small) symxsize(3) symysize(3)  pos(6) ring(1) cols(6) ///
		label(1 "Other financial wealth") label(2 "Retirement wealth") ///
		label(3 "Total financial wealth")) saving(Figures/temp4.gph, replace)
		
  * change in fin wealth by netwealth
	graph bar (mean)  del_hhnetinc_perc_tr02,  ///
		over(gender, relabel(1 "Male" 2 "Female") label(labsize(vsmall))) b1title("Gender",  size(small)) ///
		  bargap(0)  /// 
		ytitle("", size(medsmall)) ///
		yline(0, lcolor(gs8) lpattern(dash)) graphregion(color(white)) bgcolor(white) ///
		ylabel(-12.5(2.5)0, nogrid)  legend(size(small) symxsize(3) symysize(3)  pos(6) ring(1) cols(6) ///
		label(1 "Other financial wealth") label(2 "Retirement wealth") ///
		label(3 "Total financial wealth")) saving(Figures/temp5.gph, replace)
		
	 * change in fin wealth by netwealth
	graph bar (mean) del_hhnetinc_perc_tr02,  ///
		over(employment_type,  relabel(1 "Full time" 2 "Part time" 3 "Retired" 4 "Self-emp" )  label(labsize(vsmall)))b1title("Employment type",  size(small)) ///
		  bargap(0)  /// 
		ytitle("", size(medsmall)) ///
		yline(0, lcolor(gs8) lpattern(dash)) graphregion(color(white)) bgcolor(white) ///
		ylabel(-12.5(2.5)0, nogrid)  legend(size(small) symxsize(3) symysize(3)  pos(6) ring(1) cols(6) ///
		label(1 "Other financial wealth") label(2 "Retirement wealth") ///
		label(3 "Total financial wealth")) 	saving(Figures/temp6.gph, replace)		
		
		
		grc1leg2 	Figures/temp1.gph ///
					Figures/temp2.gph ///
					Figures/temp3.gph ///
					Figures/temp4.gph ///
					Figures/temp5.gph ///
					Figures/temp6.gph ///
					, cols(3) rows(2) ysize(2) xsize(3) ///
					ring(0) pos(0) holes(7) legendfrom(Figures/temp1.gph) lsize(vsmall) 
		
			graph export Figures/FigureA20.pdf, as(pdf)  fontface("cmr10") replace	
			graph export Figures/FigureA20.png, width(1600) replace 
			

forvalues x = 1/6 {
		capture erase Figures/temp`x'.gph
}						
									
